/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import {soundex} from './soundex-code'
import {str, str100K} from './string'
// 生成固定长度的编码
function soundex_test_01(){
    let a1;
    let start=Date.now();
    for(let i=0;i<500;i++){
     a1 = soundex(str)
    }
    let end=Date.now()
    if(a1!=='T131'){
        throw new Error('soundex-code_soundex err')
    }
    print(`soundex-code_soundex(value): ${end-start} ms`)
}

function soundex_test100K_01(){
    let a1;
    let start=Date.now();
    for(let i=0;i<1;i++){
     a1 = soundex(str100K)
    }
    let end=Date.now()
    if(a1!=='T131'){
        throw new Error('soundex-code_soundex err')
    }
    print(`soundex-code_soundex100k(value): ${end-start} ms`)
}

// 生成指定长度的编码
function soundex_test_02(){
    let a1;
    let start=Date.now();
    for(let i=0;i<500;i++){
     a1 = soundex(str,10)
    }
    let end=Date.now()
    if(a1!=='T131516252'){
        throw new Error('soundex-code_soundex err')
    }
    print(`soundex-code_soundex(value,maxLength): ${end-start} ms`)
    // print(a1)
}

// 生成指定长度的编码
function soundex_test100K_02(){
    let a1;
    let start=Date.now();
    for(let i=0;i<1;i++){
     a1 = soundex(str100K,10)
    }
    let end=Date.now()
    if(a1!=='T131516252'){
        throw new Error('soundex-code_soundex err')
    }
    print(`soundex-code_soundex100k(value,maxLength): ${end-start} ms`)
    // print(a1)
}

let loopCountForPreheat = 1;
for (let i = 0; i < loopCountForPreheat; i++) {
    soundex_test_01()
    soundex_test100K_01()
    soundex_test_02()
    soundex_test100K_02()

}

ArkTools.waitAllJitCompileFinish();

soundex_test_01()
soundex_test100K_01()
soundex_test_02()
soundex_test100K_02()
